# -*- coding: utf-8 -*-



import sys
from PyQt5.QtWidgets import QApplication
from PyQt5.QtCore import QEvent, QTimer
import random
from PyQt5 import QtCore, QtGui, QtWidgets


# def run():
#         count = 0
#         app = QtCore.QCoreApplication.instance()
#         while count < 5:
#             print("Increasing")  # break here
#             count += 1
#         app.quit() 

# run()

# def test_cc():
#     """测试函数"""
#     from datetime import datetime
#     try:
#         from PyQt5.QtCore import QCoreApplication
#     except ImportError:
#         from PyQt4.QtCore import QCoreApplication
    



#     def simpletest(event):
#         print(u'处理每秒触发的计时器事件：%s' % str(datetime.now()))
    
#     QCoreApplication.setEventDispatcher(QtCore.eventDispatcher)
#     app = QCoreApplication(['VnTrader'])
#     app.eventDispatcher
#     # QCoreApplication::setEventDispatcher(new EventDispatcherLibEvent);
#     # app.setEventDispatcher


#     print "--------"

#     ee = EventEngine2()
#     ee.register(EVENT_TIMER, simpletest)
#     ee.start()
    
#     app.exec_()

# test_cc()


# class MyTool(QtWidgets.QMainWindow):
#     def __init__(self):
#         '''
#         Initialize
#         '''
#         super(MyTool, self).__init__()
#         # QtGui.QApplication.instance().installEventFilter(self)
        
#     def eventFilter(self, obj, event):
#         '''
#         Event filter for rerouting wheelEvents away from combo boxes.
#         '''
#         print "======"
#         if event.type() == QtCore.QEvent.Clipboard:
#             print "ccccc"
#         # if event.type() == QtCore.QEvent.Wheel and isinstance(obj, QtGui.QComboBox):
#             #this handles all the wheel events for the combo boxes
#             # event.ignore()
#             # return True
#         # else:
#         return False
#         # return super(MyTool, self).eventFilter(obj, event)
    
#     # def closeEvent(self, e):
#     #     '''
#     #     Make sure the eventFilter is removed
#     #     '''
#     #     # QtGui.QApplication.instance().removeEventFilter(self)
#     #     return super(LightKitEditor, self).closeEvent(e)

def tttt():
    print "xxxx"
""" 
processEvents(flags: typing.Union['QEventLoop.ProcessEventsFlags', 'QEventLoop.ProcessEventsFlag'], maxtime: int) -> None
param flags: typing.Union['QEventLoop.ProcessEventsFlags', 'QEventLoop.ProcessEventsFlag']
"""


class qqq(QtGui.QGuiApplication):
    def __init__(self):
        super(qqq, self).__init__([""])

# def event(self, a0: QtCore.QEvent) -> bool: ...
    # def event(self, event):
    #     print "====", event
    #     return super(qqq, self).event(event)

    def notify(self, reciver, event):
        print event, reciver
        # if reciver == 
        # <PyQt5.QtCore.QSocketNotifier
        print event.type(), QtCore.QEvent.Clipboard
        if QtCore.QSocketNotifier == type(reciver):
            print "xxx"
            # return False
        # if event.type() == QtCore.QEvent.Clipboard:  # 40
        # if event.type() == QtCore.QEvent.MetaCall:  # 43
        if event.type() == QtCore.QEvent.DeferredDelete:  # 52
            
            print "====="
            # return False
        return super(qqq, self).notify(reciver, event)

# app = QApplication([])
app = qqq()

# app.installEventFilter(MyTool())


cb = app.clipboard()
# cb.installEventFilter(MyTool())

t = 'test02%d'%(random.randint(100,999))
print t
cb.setText(t)
# event = QtCore.QEvent(QtCore.QEvent.Clipboard)
# QtGui.QGuiApplication.sendEvent(cb, event)

# app.connectNotify(tttt)
# app.signal
# app.notify( QtCore.QEvent.Clipboard)
QTimer.singleShot(70, app.quit)
app.exec_()
# sys.exit(app.exec_())
print t
